import 'package:flutter/material.dart';
import 'package:flutterappyidongjingfen/BrowseAll/BrowseAllPage.dart';
import 'package:flutterappyidongjingfen/Financial/FinancialPage.dart';
import 'package:flutterappyidongjingfen/GroupBusiness/GroupBusinessPage.dart';
import 'package:flutterappyidongjingfen/SameBusiness/SameBusinessPage.dart';

class tabBarPage extends StatefulWidget{
  @override
  _tabBarPageState createState() => _tabBarPageState();
}

class _tabBarPageState extends State<tabBarPage>{

  var _currentIndex = 0;

  BrowseAllPage browsePage;
  FinancicalPage financicalPage;
  GroupBusinessPage grounpPage;
  SameBusinessPage sameBusinessPage;

  currentPage(){
    switch(_currentIndex){
      case 0:
        if(browsePage == null){
          browsePage = BrowseAllPage();
        }
        return browsePage;
      case 1:
        if(financicalPage == null){
          financicalPage = FinancicalPage();
        }
        return financicalPage;
      case 2:
        if(sameBusinessPage == null){
          sameBusinessPage = SameBusinessPage();
        }
        return sameBusinessPage;
      case 3:
        if(grounpPage == null){
          grounpPage = GroupBusinessPage();
        }
        return grounpPage;
      default:
    }
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  /*
  icon_browseAll_tabBarItem_selected.png
icon_browseAll_tabBarItem_normal@2x.png
icon_financical_tabBarItem_normal.png
icon_financical_tabBarItem_normal@2x.png
icon_groupBusiness_tabBarItem_normal.png
icon_groupBusiness_tabBarItem_normal@2x.png
icon_groupBusiness_tabBarItem_selected.png
icon_groupBusiness_tabBarItem_selected@2x.png
icon_sameBusiness_tabBarItem_normal.png
icon_sameBusiness_tabBarItem_normal@2x.png
icon_sameBusiness_tabBarItem_selected.png
icon_sameBusiness_tabBarItem_selected@2x.png
   */

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.black,
      bottomNavigationBar: BottomNavigationBar(

          items: [
            BottomNavigationBarItem(
              icon: _currentIndex == 0 ? Image.asset("images/icon_browseAll_tabBarItem_selected.png",fit:BoxFit.cover,width: 32.0,height: 28.0,) : Image.asset("images/icon_browseAll_tabBarItem_normal.png",fit:BoxFit.cover,width: 32.0,height: 28.0,),
              title: Text(
                "总览",
                style: TextStyle(
                  fontSize: 12.0,
                  color: _currentIndex == 0 ? Color(0xFF119CFD) : Color(0xFF6C7390),
                ),
              ),
            ),
            BottomNavigationBarItem(
              icon: _currentIndex == 1 ? Image.asset("images/icon_financical_tabBarItem_selected.png",width: 32.0,height: 28.0,) : Image.asset("images/icon_financical_tabBarItem_normal.png",width: 32.0,height: 28.0,),
              title: Text(
                "财务",
                style: TextStyle(
                  fontSize: 12.0,
                  color: _currentIndex == 1 ? Color(0xFF119CFD) : Color(0xFF6C7390),
                ),
              ),
            ),
            BottomNavigationBarItem(
              icon: _currentIndex == 2 ? Image.asset("images/icon_sameBusiness_tabBarItem_selected.png",width: 32.0,height: 28.0,) : Image.asset("images/icon_sameBusiness_tabBarItem_normal.png",width: 32.0,height: 28.0,),
              title: Text(
                "同业",
                style: TextStyle(
                  fontSize: 12.0,
                  color: _currentIndex ==  2 ? Color(0xFF119CFD) : Color(0xFF6C7390),
                ),
              ),
            ),
            BottomNavigationBarItem(
              icon: _currentIndex == 3 ? Image.asset("images/icon_groupBusiness_tabBarItem_selected.png",width: 32.0,height: 28.0,) : Image.asset("images/icon_groupBusiness_tabBarItem_normal.png",width: 32.0,height: 28.0,),
              title: Text(
                "团金",
                style: TextStyle(
                  fontSize: 12.0,
                  color: _currentIndex == 3 ? Color(0xFF119CFD) : Color(0xFF6C7390),
                ),
              ),
            ),
          ],
//        backgroundColor: Colors.red,
        backgroundColor: Color.fromRGBO(11, 13, 28, 1),
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (index){
            setState(() {
              if(_currentIndex == index){
                return;
              };
              _currentIndex = index;
            });
        },
      ),
      body: currentPage(),
    );
  }
}